package com.iams.manage.validator;


import com.iams.common.utils.SecurityUtils;
import com.iams.manage.domain.Archive;
import com.iams.manage.domain.ArchiveDestroyApproval;
import com.iams.manage.domain.ArchiveFilingApproval;
import com.iams.manage.mapper.ArchiveMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ArchiveFilingApprovalValidator {

    @Autowired
    private ArchiveMapper archiveMapper;
    public void validate(ArchiveFilingApproval archiveFilingApproval)
    {

        if(archiveMapper.selectArchiveById(archiveFilingApproval.getArchiveId())==null)
        {
            throw new RuntimeException("档案不存在");
        }
        Archive archive = archiveMapper.selectArchiveById(archiveFilingApproval.getArchiveId());
        if(!archive.getDanghao().equals(archiveFilingApproval.getDanghao())||!archive.getName().equals(archiveFilingApproval.getArchiveName()))
        {
            throw new RuntimeException("档案信息不匹配，请检查输入的档号或档案名");
        }

        if(!archiveFilingApproval.getUserId().equals(SecurityUtils.getLoginUser().getUserId())
                ||!archiveFilingApproval.getDeptId().equals(SecurityUtils.getLoginUser().getDeptId())
                ||!archiveFilingApproval.getUserName().equals(SecurityUtils.getLoginUser().getUsername()))
        {
            throw new RuntimeException("用户信息有误");
        }


    }
}
